<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>promise</title>
</head>
<body>
    
    <script>
    
    function createPromise (state) {
        return new Promise((resolve,reject)=>{
            setTimeout(function () {
                if(state){
                    resolve('success');
                }else {
                    reject('failed');
                }
            },2000)
        });
    }

    let p1 = createPromise (1);

    p1.then(res=>{
        console.log(res);
    },err=>{
        console.log(err);
    })
    
    console.log('js代码');

    </script>

</body>
</html>